package com.keyingbo.leran.pattern.singletonpattern.container;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Auther: KEYB
 * @Date: 2019-3-12 11:03
 * @Description:
 */
public class ContainerSingleton {
    private static Map<String,Object> beanMap = new ConcurrentHashMap<String, Object>();
    public static Object getBeanObject(Class clazz){
        if (beanMap.get(clazz.getName()) == null) {
            Object object = null;
            try {
                 object = clazz.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            beanMap.put(clazz.getName() , object);
            return  object;
        }
        return beanMap.get(clazz.getName());
    }
}
